package org.aeon.heroicsagatextedition.game;

import org.aeon.heroicsagatextedition.Input.InputFactory;
import org.aeon.heroicsagatextedition.output.OutputFactory;

import java.lang.reflect.Method;

import static org.aeon.heroicsagatextedition.constants.Color.*;
import static org.aeon.heroicsagatextedition.utils.FontColors.coloring;

/**
 * @projectName: HeroicSagaTextEdition
 * @package: org.aeon.heroicsagatextedition.game
 * @className: GameMenu
 * @author: MissingAeon
 * @date: 2023/12/22 13:21
 * @description: 游戏菜单类，处理游戏开始、继续和退出等菜单选项。
 */
public class GameMenu {
    private static final GameMenu gameMenu = new GameMenu();

    public static GameMenu getGameMenu() {
        return gameMenu;
    }

    /**
     * 菜单显示
     */
    public Method displayMenu(Class<? extends Game> clazz) throws NoSuchMethodException {
        while (true) {
            OutputFactory.create().print();
            OutputFactory.create().print("******** ", coloring("魔幻英雄v1.0", BRIGHT_CYAN), " ********");
            OutputFactory.create().print("  1. 开始新游戏");
            OutputFactory.create().print("  2. 继续游戏");
            OutputFactory.create().print("  3. 退出游戏");
            System.out.print("请输入您的选择: ");
            int select = InputFactory.create().scanInt();
            switch (select) {
                case 1 -> {
                    return clazz.getDeclaredMethod("newGame");
                }
                case 2 -> {
                    return clazz.getDeclaredMethod("continueGame");
                }
                case 3 -> {
                    return clazz.getDeclaredMethod("quit");
                }
                default -> GameMenu.getGameMenu().selectError();
            }
        }

    }

    /**
     * 错误处理
     */
    public void selectError() {
        OutputFactory.create().print(coloring("错误的选项！", BACKGROUND_RED,BLACK));
        InputFactory.create().pauseBeforeInput();
    }

}
